#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
queue<int> q[5010];
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		v.push_back(t);
	}
	while(k--)
	{
		char op;
		cin>>op;
		if(op=='Z')
		{
			int x,y;
			cin>>x>>y;
			if(x>=v.size())
			{
				v.push_back(y);
			}
			else
			{
				v.insert(v.begin()+x,y);
			}
		}
		else
		{
			int x;
			cin>>x;
			if(x<v.size())
			v.erase(v.begin()+x);
		}
	}
	cout<<v.size()<<endl;
	for(auto it:v) cout<<it<<' ';

	return 0;
}

